Managing memory in a computer system

ABSTRACT

Methods, computer program products, and systems for managing memory in a computer system in which memory locations in use at any given time are represented as a set of memory objects in a first object graph. The first object graph includes a system root object associated by references to each of the memory objects. A method includes creating a second root object for the memory to form a second object graph for the memory. The method also includes, in response to the dereferencing of a first object from the first object graph, associating the dereferenced first object with the second object graph so that the second object graph includes at least one dereferenced object.

PRIORITY

This application is a continuation of application Ser. No. 15/211,311,filed 15 Jul. 2016, which is a continuation of application Ser. No.13/870,028, filed 25 Apr. 2013, which claims priority to Great BritainPatent Application No. 1208434.9, filed 15 May 2012, and all thebenefits accruing therefrom under 35 U.S.C. § 119. The contents of U.S.application Ser. No. 15/211,311, U.S. application Ser. No. 13/870,028,and Great Britain Patent Application No. 1208434.9 are hereinincorporated by reference in their entireties.

BACKGROUND

The present invention relates to a computer system, and moreparticularly, to managing memory in a computer system.

Computer systems commonly use a virtual memory management system.Virtual memory management systems use dynamic memory allocationprocesses and garbage collection processes to respectively allocate andreclaim memory allocations. The garbage collection process is arrangedto identify allocated but unusable memory allocations, clear theassociated memory objects they store and return the identified memoryallocations for reuse by reallocation.

The garbage collection process requires significant processing power andmay delay other processing by the computer. The memory efficiency ofapplication programs can be improved so that fewer discarded memoryobjects are produced for the garbage collection process to clear.However, with multiple system or application programs running on a givencomputer, identifying the source of discarded memory objects isdifficult and time consuming.

SUMMARY

Embodiments include methods, computer program products, and systems formanaging memory in a computer system in which memory locations in use atany given time are represented as a set of memory objects in a firstobject graph. The first object graph includes a system root objectassociated by references to each of the memory objects. A methodincludes creating a second root object for the memory so as to form asecond object graph for the memory. The method also includes, inresponse to the dereferencing of a first object from the first objectgraph, associating the dereferenced first object with the second objectgraph so that the second object graph includes at least one dereferencedobject.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

Embodiments of the present invention will now be described, by way ofexample only, with reference to the following drawings in which:

FIG. 1 is a schematic illustration of a computer system comprising avirtual machine in accordance with an embodiment;

FIGS. 2a and 2b are schematic representations of object graphs in thememory of the virtual machine of FIG. 1 in accordance with anembodiment;

FIG. 3 is a table illustrating data extracted from one of the objectgraphs of FIG. 2b in accordance with an embodiment;

FIG. 4 is a flow chart illustrating processing performed in the computersystem in response to the dereferencing of an object in the object graphof FIG. 2a in accordance with an embodiment; and

FIG. 5 is a flow chart illustrating processing performed in response toa garbage collection process performed on the object graph of FIG. 2bresulting in the data of FIG. 3 in accordance with an embodiment.

DETAILED DESCRIPTION OF THE EMBODIMENTS

Embodiments of the present invention are directed to managing memory ina computer system in which memory locations in use at any given time arerepresented as a set of memory objects in a first object graph. Thefirst object graph includes a system root object associated byreferences to each of the memory objects. Methods include creating asecond root object for the memory so as to form a second object graphfor the memory. In response to the dereferencing of a first object fromthe first object graph, the dereferenced first object is associated withthe second object graph so that the second object graph includes one ormore dereferenced objects.

Methods may also include identifying a second object in the first objectgraph that referenced the first object immediately prior to thedereferencing of the first object and creating a reference from thesecond object graph to the second object so as to associate the firstobject in the second object graph with the second object in the firstobject graph. Methods may also include creating a first metadata objectin the second object graph the first metadata object being arranged toprovide the reference from the second object graph to the second objectin the first object graph and to reference the first object in thesecond object graph. Methods may further include identifyingpredetermined metadata for the first object identifying the location ofthe first object in the first object graph immediately prior to thedereferencing; and storing the metadata in the second object graph inassociation with the first object.

The metadata may be stored in a second metadata object associated withthe first object in the second object graph. The metadata may includedata identifying a field in the second object used to reference thefirst object immediately prior to the dereferencing of the first objectfrom the second object.

Methods may also include, in response to a first stage of garbagecollection in which a first set of objects including all objects presentin the first object graph being identified, identifying a second set ofobjects that include objects present in the second object graph and notpresent in the first object graph. Predetermined data associated witheach of the objects in the second set of objects is saved prior to anyfurther stage of garbage collection in which the second set of objectsis deleted from the memory. The predetermined data may include dataidentifying the first object. The predetermined data may include dataidentifying the second object that referenced the first objectimmediately prior to the dereferencing of the first object. Thepredetermined data may include data identifying the field in the secondobject that referenced the first object in the first object graphimmediately prior to the dereferencing.

Other embodiments provide an apparatus for managing memory in a computersystem in which memory locations in use at any given time arerepresented as a set of memory objects in a first object graph thatincludes a system root object associated by references to each of thememory objects. The apparatus may be operable to create a second rootobject for the memory so as to form a second object graph for thememory, and in response to the dereferencing of a first object from thefirst object graph, associate the dereferenced first object with thesecond object graph so that the second object graph includes one or moredereferenced objects.

Further embodiments provide a computer program product for managingmemory in a computer system in which memory locations in use at anygiven time are represented as a set of memory objects in a first objectgraph that includes a system root object associated by references toeach of the memory objects. The computer program product may include acomputer-readable storage medium having computer-readable program codeembodied therewith, the computer-readable program code configured to:create a second root object for the memory so as to form a second objectgraph for the memory; and in response to the dereferencing of a firstobject from the first object graph, associate the dereferenced firstobject with the second object graph so that the second object graphincludes one or more dereferenced objects.

Embodiments of the invention are arranged to preserve data relating tomemory objects removed from the system object graph for use inidentifying the source of such removed objects.

With reference to FIG. 1, a computer 101 is loaded with an operatingsystem 102, which provides a processing platform for one or moreapplication programs. In the present embodiment, the computer is loadedwith a virtual machine environment application program 103, in the formof a Java runtime environment (JRE) application program, arranged toenable a user to run one or more Java virtual machines (JVMs) 104 on thecomputer 101. Each JVM 104 includes virtual memory 105 and a memorymanager program 106 that includes a garbage collection module 107. EachJVM 104 further includes storage 107 arranged to store one or moreprograms 108 for running on the JVM 104 and to store input or outputprogram data 109.

The memory manager 106 is arranged to manage the use of the memory 105during the processing by the JVM 104 of one of the programs 108 byallocating or de-allocating portions of the memory 105 to the program108 as required. The memory manager 106 periodically performs a garbagecollection process to scan the memory 105 to identify portions of thememory 105 that have been de-allocated by a program 108, clear data fromany such portions of memory and mark the portions of memory as availablefor further allocation by the memory manager 106 to a program 108.

In the memory model for the JVM 104 the memory 105 is initially free andallocated to a memory management data construct call the heap from whichlocations in the memory 105 are allocated on request from a program 108for storage of a memory object in the form of a variable, function ordata structure. With reference to the embodiment shown in FIG. 2a , thememory objects 201 in use at any given time by a program 108 may beassociated by means of references 202 from one object 201 to another soas to form a first object graph 203 in the form of a system objectgraph. The system object graph 203 shown in FIG. 2a includes a rootobject 204 referred to as the system root. In other words, the currentor live data objects for a program 108 are all associated by references202 to the system root 204 either directly or indirectly via one or moreother objects 201. Any given object 201 may be referenced by any numberof other objects 201. In other words, a given object 201 may be linkedor associated with any number of other objects 201 by references fromeach of those other objects 201.

When a reference 202 to a given object 201 is no longer required by aprogram 108, the relevant reference 202 is removed from the object graph203. In other words, the object 201 is de-referenced. However, since anobject 201 may be referenced by any number of other objects 201, theremoval of one reference does not necessarily indicate that the objecthas been discarded. Only once all references 202 to a given object havebeen removed can the object 201 be treated as discarded. Since allreferences 202 to a discarded object 201 will thus have been removed,the discarded object will no longer be linked or associated with thesystem root 204. The garbage collection process of the memory manager106 is arranged to traverse the object graph for the memory 105 andidentify all objects 201 that are linked either directly or indirectlyto the system root 204. Such objects are referred to as live objects,that is, objects that are currently in use by the relevant program 108.All other objects 201 are treated as discarded or dead objects and canthus be removed from memory 105 and their allocated memory returned tothe heap for reuse.

In an embodiment, the memory manager 106 is arranged to collect data forobjects 201 in response to their dereferencing. During the garbagecollection process, the memory manager 106 is further arranged, for anydereferenced object that is dead and to be discarded, to save apredetermined set of data relating to the dead object in the form ofdead object data 110 shown in FIG. 1. In an embodiment, the dead objectdata includes an identification of the dead object, a reference to thelive object from which the dead object was de-referenced, and fieldmetadata identifying the field in the live object that contained theremoved reference to the dead object.

With reference to the embodiment shown in FIG. 2b , in order to collectthe dead object data 110, the memory manager 106 is arranged to maintaina second object graph 205 for the memory 105 which includes thedereferenced objects. In an embodiment, the second object graph 205includes a root object 206 referred to herein as the dead root. Thememory manager 106 is arranged, in response to the dereferencing of anobject from the first object graph 203, that is, the system root objectgraph, to add the dereferenced object to the dereferenced object graph205. In an embodiment, this is implemented by adding a new object to thedereferenced object graph 205 in the form of a dead object informationobject 207. In an embodiment, all new dead object information objectsare referenced directly from the dead root object 206. The dead objectinformation object 207 includes a reference 208 to the newlydereferenced object 209. In an embodiment, the dead information object207 further includes a reference 210 to the live object 201 from whichthe dereferenced object 209 was de-referenced. A field definition object211 is also added to the dereferenced object graph 205 and referencedfrom the dead object information object 207. The field definition object211 includes data identifying the field in the live object 201 thatcontained the removed reference to the newly dereferenced object 209.

The garbage collection process performed by the memory manager 106 isarranged, in a first phase commonly referred to as the marking phase, tosearch the system root object graph 203 and mark all connected objectspresent as “live”. In other words, all objects that are referencedeither directly from the system root 204 or indirectly from the systemroot 204 via one or more other objects 201 in the system root objectgraph 203 are identified as currently in use by a loaded program 108.The dereferenced object graph 205 not used for identifying “live”objects. Nevertheless, some of the objects identified via the systemroot object graph 203 may also be present in the dereferenced objectgraph 205. This occurs where a dereferenced object is referenced by morethan one live object and one or more such references remain when thegarbage collection process is performed.

In a second phase of the garbage collection process, the memory manager106 is arranged to search the dereferenced object graph 205 to identifyany connected object 209 that was not identified as “live” in the firstphase and is thus a candidate for removal or sweeping form the memory105. The garbage collection is arranged to exclude from this search anymetadata objects, that is, in the present embodiment, the deadinformation objects 207 and the field definition objects 211. Thisavoids the unnecessary processing by the garbage collection process ofmetadata objects, which, in the present embodiment, are never referencedby a “live” object. For each such candidate object the associatedobjects in the form of the dead object information object 207 and themetadata object 211 that were created on dereferencing of the object areidentified and the predetermined dead object data 110 extracted andstored as shown in the embodiment shown in FIG. 3. Thus, for eachrelevant object, the dead object data 110 firstly includes an objectidentifier 301 identifying the dead object 209. Secondly the dead objectdata 110 includes an identification 302 of the original parent 201 ofthe dead object 209 that is the object 201 that originally referencedthe dead object 209. The identification 302 is derived from thereference 210 from the dead object information object 207 to theoriginally referencing object 201. Thirdly the dead object data 110includes referencing field data 303 identifying the field in the object201 that was used for originally referencing the dead object 209. Thereferencing field data 303 is extracted from the field definition object211 referenced from the dead object information object 207.

Some objects may be present in the dereferenced object graph 205 thatremain referenced from one or more live objects in the system rootobject graph 203 and thus remain “live”. However, in the first phase ofthe garbage collection process the metadata objects associated with suchdereferenced but still “live” objects will not get marked as “live” asthey are inaccessible from the system root 204 and will thus becandidates for removal. Therefore, in order to preserve the metadataobjects for such dereferenced but still “live” objects, the memorymanager 106 is further arranged to identify any of the dereferencedobjects in the second object graph 205 marked as “live” and to similarlymark their associated metadata objects as “live” to avoid theirsubsequent removal.

Once the dead object data 110 has been extracted from the relevant nodesof the dereferenced object graph 205 a third phase in the garbagecollection process is initiated, commonly referred to as the sweepingphase. In this third phase, all objects in the memory 105 are scannedand all objects not marked as “live” are removed and their memoryallocation returned to the heap for reuse. Where objects are removedfrom memory 105, the dereferenced object graph 205 is repaired to removethe now redundant metadata objects, that is, in an embodiment, therelevant dead information objects 207 and the field definition objects211. Some objects may remain in the dereferenced object graph 205 asthey are still referenced from one or more live objects in the systemroot object graph 203.

An embodiment of the processing performed by the memory manager 106 inresponse to the dereferencing of an object will now be described withreference of the flow chart of FIG. 4. Processing is initiated at block401 in response to the selection of an object for dereferencing andprocessing then moves to block 402. At block 402, the selected object isdereferenced from the system root object graph 203 and processing movesto block 403. At block 403, if no dead root object currently exists inthe memory 105 then processing moves to block 404. At block 404, a deadroot object 206 is created and processing moves to block 405. If, atblock 403, a dead root object 206 is identified in the memory 105 thenprocessing moves straight to block 405. At block 405, a new dead objectinformation object 207 is created and a reference is added from the deadroot object 206 to the new dead object information object 207 andprocessing moves to block 406. At block 406, a reference is added fromthe new dead object information object 207 to the live object 201 thatreferenced the newly dereferenced object 209 immediately prior to itsdereferencing and processing moves to block 407. At block 407, areference is added from the new dead object information object 207 tothe newly dereferenced object 209 and processing moves to block 408. Atblock 408, a new metadata object 211 is created and data identifying thefield in the prior referencing object 201 that provided the reference tothe newly dereferenced object 209 and processing moves to block 409. Atblock 409, a reference to the new metadata object 211 is added to thedead object information object 207. Processing then moves to block 410and ends.

An embodiment of the processing performed by the memory manager 106 inthe garbage collection process will now be described with reference ofthe flow chart of FIG. 5. Processing is initiated at block 501 inaccordance with the garbage collection scheduling of the memory manager106 and processing then moves to block 502. At block 502, the systemroot object graph 203 is traversed and all accessible objects marked aslive and processing moves to block 503. At block 503, the dereferencedobject graph 205 is traversed to identify any dereferenced objectsmarked as “live”, identify their associated metadata objects and markthose objects as “live” and processing moves to block 504. At block 504,the dereferenced object graph 205 is traversed to identify any connectedobject 209 that was not identified as “live” in block 502 and is thus acandidate object for removal from memory 105 and processing moves toblock 505. At block 505, for each identified candidate for removal, thedead object data 110 is extracted from the relevant objects in thedereferenced object graph 205 and stored and processing moves to block506. At block 506, all candidate objects for removal identified in block502 are removed from memory and their memory allocations returned to theheap and processing moves to block 507. At block 507, the dereferencedobject graph 205 is repaired where necessary to consider the removedobjects. Processing then moves to block 508 and ends.

In another embodiment, the dead object data includes an identificationof closest live object that references a given dead object eitherdirectly or indirectly via one or more other dead objects.

In a further embodiment, the memory manager provides memory allocationsfrom two heaps. The first heap provides storage for all objects and thesecond heap provides storage for the dead root object and the metadataobjects such as the dead information objects and the field definitionobjects. In response to the dereferencing of an object in the firstheap, a corresponding set of metadata objects is created in the secondheap including a cross-heap reference to the dereferenced object in thefirst heap. When the garbage collection process is applied to the firstheap any dereferenced object with no further references from liveobjects will be identified as a candidate for removal. The cross-heapreference from the metadata objects in the second heap will not bevisible and thus not disrupt the identification of the dereferencedobject by the garbage collection process. For each object identified asa candidate for removal, the second heap is scanned to identify andoutput the associated object metadata. The cross-heap reference from themetadata to the associated object in the first heap is then removed. Asecond garbage collection process is then performed on the second heapstarting from the dead root and arranged to identify and remove anymetadata objects not connected to a live object, that is, without across-heap reference to a live object.

As will be understood by those skilled in the art embodiments of theinvention are not limited to Java or the JRE and may be applied to anyvirtual machine system or environment. Suitable virtual machine systemsor environments may be arranged to run directly on a computer system orrun on an operating system. In other words, the virtual machine systemor environment may run natively or be hosted. The virtual machines maybe provided by software emulation or hardware virtualization.

As will be understood by those skilled in the art, embodiments of theinvention may be applied to the physical machine environment, that is,to operating systems running directly on a physical computer andproviding a platform for running one or more application programs.

As will be understood by those skilled in the art any suitable level ofdead object data may be provided for a given application. In someapplications, minimal dead object data may be provided which provides asingle data item for each dead object such as an identifier for the deadobject or an identification of the object that referenced the deadobject immediately prior to its dereferencing or an identification ofclosest live object that references a given dead object either directlyor indirectly via one or more other dead objects.

Embodiments of the invention reference the metadata objects associatedwith dereferenced objects from the dead root and the dereferenced objectitself is referenced from the metadata. This avoids the need foradditional fields in objects for referencing their respective metadata.Such additional fields may need to be hidden in some implementations.

Embodiments of the invention are arranged to preserve data relating tothe memory objects that have been created during the processing ofprograms on a computer that have subsequently been removed from memoryas a result of a garbage collection process or other suitable memorymanagement process. The data may include an identification of theremoved objects or detail of the objects that were associated with theremoved object or referenced the removed object. The data may includeidentification of the fields of referencing objects from which theremoved object was referenced. The dead object data can be used foridentifying the programs, parts of programs or other processes thatcreated the respective objects. Such identification is useful formonitoring, measuring, modifying or improving the memory usage of therelevant program, program part or other process. The data may be usedfor reconstructing the system object graph at selected points in theassociated processing.

It will be understood by those skilled in the art that the apparatusthat embodies a part or all the present invention may be ageneral-purpose device having software arranged to provide a part or allan embodiment of the invention. The device could be a single device or agroup of devices and the software could be a single program or a set ofprograms. Furthermore, any or all of the software used to implement theinvention can be communicated via any suitable transmission or storagemeans so that the software can be loaded onto one or more devices.

While the present invention has been illustrated by the description ofthe embodiments thereof, and while the embodiments have been describedin considerable detail, it is not the intention of the applicant torestrict or in any way limit the scope of the appended claims to suchdetail. Additional advantages and modifications will readily appear tothose skilled in the art. Therefore, the invention in its broaderaspects is not limited to the specific details of the representativeapparatus and method, and illustrative examples shown and described.Accordingly, departures may be made from such details without departurefrom the scope of applicant's general inventive concept.

What is claimed is:
 1. A computer program product comprising a computerreadable storage medium having program code embodied therewith, theprogram code executable by a processor to cause the processor to performa method comprising: identifying one or more candidate objects in adereferenced object graph, the dereferenced object graph including a setof objects that were dereferenced from a system root object graph, theone or more candidate objects being connected objects in thedereferenced object graph; extracting dead object data from the one ormore candidate objects; removing, after extracting the dead object datafrom the one or more candidate objects, the one or more candidateobjects from memory; storing the extracted dead object data in thedereferenced object graph; and repairing the dereferenced object graph.2. The computer program product of claim 1, wherein the identifying oneor more candidate objects in the dereferenced object graph comprises:traversing the dereferenced object graph to identify one or moredereferenced objects in the dereferenced object graph that are marked aslive, wherein the one or more candidate objects include objects in thedereferenced object graph that are not marked as live.
 3. The computerprogram product of claim 2, wherein the method performed by theprocessor further comprises: identifying metadata objects associatedwith the one or more live dereferenced objects; marking the metadataobjects as live; and returning, after removing the one or more candidateobjects from memory, memory allocations of the one or more candidateobjects to a heap.
 4. The computer program product of claim 3, whereinthe candidate objects do not include metadata objects, and wherein themetadata objects include dead information objects and field definitionobjects.
 5. The computer program product of claim 1, wherein the deadobject data for a candidate object includes an object identifier thatidentifies the candidate object, an identification of a parent object ofthe candidate object, and referencing field data that identifies a fieldin the parent object that referenced the candidate object.
 6. Thecomputer program product of claim 5, wherein the parent object of thecandidate object is an object in the system root object graph thatindirectly references the candidate object via one or more dead objects.7. The computer program product of claim 1, wherein the repairing thedereferenced object graph includes removing redundant metadata objectsfrom the dereferenced object graph.
 8. The computer program product ofclaim 1, wherein the method performed by the processor furthercomprises: providing, by a memory manager, memory allocations from afirst heap and a second heap, the first heap including storage forconnected objects, the second heap including storage for a dead rootobject and metadata objects; and creating, in response to dereferencingan object in the first heap, a corresponding set of metadata objects inthe second heap, the corresponding set of metadata objects including across-heap reference to the dereferenced object in the first heap. 9.The computer program product of claim 1, wherein the method performed bythe processor further comprises: marking one or more connected objectsin the system root object graph as live, wherein the one or moreconnected objects represent memory locations in use by a program at agiven time; creating a dead root object so as to form the dereferencedobject graph; and in response to a dereferencing of a first object fromthe system root object graph, associating the dereferenced first objectwith the dereferenced object graph so that the dereferenced object graphcomprises one or more dereferenced objects.
 10. The computer programproduct of claim 1, wherein storing the extracted dead object data inthe dereferenced object graph includes replacing the one or morecandidate objects in the dereferenced object graph with associated deadobject data.
 11. The computer program product of claim 10, wherein thesystem root object graph is associated with an application, and whereinthe method performed by the processor further comprises: identifying,using the dead object data, one or more processes that created thedereferenced objects, the one or more processes being part of theapplication; reconstructing the system root object graph using the deadobject data at a selected point in the associated processing of theapplication; and modifying the application to improve memory usage ofthe processes.